<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>DragDrop.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - Drag &amp; Drop
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font>
<font color="#924B72">#Window</font> = 0

<b><font color="#3A3966">Enumeration</font></b>    <font color="#3A3966">; Images
</font>  <font color="#924B72">#ImageSource</font>
  <font color="#924B72">#ImageTarget</font>
<b><font color="#3A3966">EndEnumeration</font></b>

<b><font color="#3A3966">Enumeration</font></b>    <font color="#3A3966">; Gadgets
</font>  <font color="#924B72">#SourceText</font>
  <font color="#924B72">#SourceImage</font>
  <font color="#924B72">#SourceFiles</font>
  <font color="#924B72">#SourcePrivate</font>
  <font color="#924B72">#TargetText</font>
  <font color="#924B72">#TargetImage</font>
  <font color="#924B72">#TargetFiles</font>
  <font color="#924B72">#TargetPrivate1</font>
  <font color="#924B72">#TargetPrivate2</font>
<b><font color="#3A3966">EndEnumeration</font></b>



<b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenWindow</font>(<font color="#924B72">#Window</font>, 0, 0, 760, 310, "Drag &amp; Drop", <font color="#924B72">#PB_Window_SystemMenu</font>|<font color="#924B72">#PB_Window_ScreenCentered</font>)
  
  <font color="#3A3966">; Create some images for the image demonstration
</font>  <font color="#3A3966">; 
</font><font color="#3A3966">  CreateImage</font>(<font color="#924B72">#ImageSource</font>, 136, 136)
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">StartDrawing</font>(<font color="#3A3966">ImageOutput</font>(<font color="#924B72">#ImageSource</font>))
<font color="#3A3966">    Box</font>(0, 0, 136, 136, $FFFFFF)
<font color="#3A3966">    DrawText</font>(5, 5, "Drag this image", $000000, $FFFFFF)
    <b><font color="#3A3966">For</font></b> i = 45 <b><font color="#3A3966">To</font></b> 1 <b><font color="#3A3966">Step</font></b> -1
<font color="#3A3966">      Circle</font>(70, 80, i,<font color="#3A3966"> Random</font>($FFFFFF))
    <b><font color="#3A3966">Next</font></b> i
    
<font color="#3A3966">    StopDrawing</font>()
  <b><font color="#3A3966">EndIf</font></b>
  
<font color="#3A3966">  CreateImage</font>(<font color="#924B72">#ImageTarget</font>, 136, 136)
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">StartDrawing</font>(<font color="#3A3966">ImageOutput</font>(<font color="#924B72">#ImageTarget</font>))
<font color="#3A3966">    Box</font>(0, 0, 136, 136, $FFFFFF)
<font color="#3A3966">    DrawText</font>(5, 5, "Drop images here", $000000, $FFFFFF)
<font color="#3A3966">    StopDrawing</font>()
  <b><font color="#3A3966">EndIf</font></b>
  

  <font color="#3A3966">; Create and fill the source gadgets
</font>  <font color="#3A3966">;
</font><font color="#3A3966">  ListIconGadget</font>(<font color="#924B72">#SourceText</font>,       10, 10, 140, 140, "Drag Text here", 130)   
<font color="#3A3966">  ImageGadget</font>(<font color="#924B72">#SourceImage</font>,        160, 10, 140, 140,<font color="#3A3966"> ImageID</font>(<font color="#924B72">#ImageSource</font>), <font color="#924B72">#PB_Image_Border</font>) 
<font color="#3A3966">  ExplorerListGadget</font>(<font color="#924B72">#SourceFiles</font>, 310, 10, 290, 140,<font color="#3A3966"> GetHomeDirectory</font>(), <font color="#924B72">#PB_Explorer_MultiSelect</font>)
<font color="#3A3966">  ListIconGadget</font>(<font color="#924B72">#SourcePrivate</font>,   610, 10, 140, 140, "Drag private stuff here", 260)
     
<font color="#3A3966">  AddGadgetItem</font>(<font color="#924B72">#SourceText</font>, -1, "hello world")
<font color="#3A3966">  AddGadgetItem</font>(<font color="#924B72">#SourceText</font>, -1, "The quick brown fox jumped over the lazy dog")
<font color="#3A3966">  AddGadgetItem</font>(<font color="#924B72">#SourceText</font>, -1, "abcdefg")
<font color="#3A3966">  AddGadgetItem</font>(<font color="#924B72">#SourceText</font>, -1, "123456789")
  
<font color="#3A3966">  AddGadgetItem</font>(<font color="#924B72">#SourcePrivate</font>, -1, "Private type 1")
<font color="#3A3966">  AddGadgetItem</font>(<font color="#924B72">#SourcePrivate</font>, -1, "Private type 2")
  

  <font color="#3A3966">; Create the target gadgets
</font>  <font color="#3A3966">;
</font><font color="#3A3966">  ListIconGadget</font>(<font color="#924B72">#TargetText</font>,  10, 160, 140, 140, "Drop Text here", 130)
<font color="#3A3966">  ImageGadget</font>(<font color="#924B72">#TargetImage</font>,    160, 160, 140, 140,<font color="#3A3966"> ImageID</font>(<font color="#924B72">#ImageTarget</font>), <font color="#924B72">#PB_Image_Border</font>) 
<font color="#3A3966">  ListIconGadget</font>(<font color="#924B72">#TargetFiles</font>, 310, 160, 140, 140, "Drop Files here", 130)
<font color="#3A3966">  ListIconGadget</font>(<font color="#924B72">#TargetPrivate1</font>, 460, 160, 140, 140, "Drop Private Type 1 here", 130)
<font color="#3A3966">  ListIconGadget</font>(<font color="#924B72">#TargetPrivate2</font>, 610, 160, 140, 140, "Drop Private Type 2 here", 130)

  
  <font color="#3A3966">; Now enable the dropping on the target gadgets
</font>  <font color="#3A3966">;
</font><font color="#3A3966">  EnableGadgetDrop</font>(<font color="#924B72">#TargetText</font>,     <font color="#924B72">#PB_Drop_Text</font>,    <font color="#924B72">#PB_Drag_Copy</font>)
<font color="#3A3966">  EnableGadgetDrop</font>(<font color="#924B72">#TargetImage</font>,    <font color="#924B72">#PB_Drop_Image</font>,   <font color="#924B72">#PB_Drag_Copy</font>)
<font color="#3A3966">  EnableGadgetDrop</font>(<font color="#924B72">#TargetFiles</font>,    <font color="#924B72">#PB_Drop_Files</font>,   <font color="#924B72">#PB_Drag_Copy</font>)
<font color="#3A3966">  EnableGadgetDrop</font>(<font color="#924B72">#TargetPrivate1</font>, <font color="#924B72">#PB_Drop_Private</font>, <font color="#924B72">#PB_Drag_Copy</font>, 1)
<font color="#3A3966">  EnableGadgetDrop</font>(<font color="#924B72">#TargetPrivate2</font>, <font color="#924B72">#PB_Drop_Private</font>, <font color="#924B72">#PB_Drag_Copy</font>, 2)

  <b><font color="#3A3966">Repeat</font></b>
    Event =<font color="#3A3966"> WaitWindowEvent</font>()
    
    <font color="#3A3966">; DragStart event on the source gadgets, initiate a drag &amp; drop
</font>    <font color="#3A3966">;
</font>    <b><font color="#3A3966">If</font></b> Event = <font color="#924B72">#PB_Event_Gadget</font> <b><font color="#3A3966">And</font></b> <font color="#3A3966">EventType</font>() = <font color="#924B72">#PB_EventType_DragStart</font>
      <b><font color="#3A3966">Select</font></b> <font color="#3A3966">EventGadget</font>()
      
        <b><font color="#3A3966">Case</font></b> <font color="#924B72">#SourceText</font>
          Text$ =<font color="#3A3966"> GetGadgetItemText</font>(<font color="#924B72">#SourceText</font>,<font color="#3A3966"> GetGadgetState</font>(<font color="#924B72">#SourceText</font>))
<font color="#3A3966">          DragText</font>(Text$)
        
        <b><font color="#3A3966">Case</font></b> <font color="#924B72">#SourceImage</font>
<font color="#3A3966">          DragImage</font>(<font color="#3A3966">ImageID</font>(<font color="#924B72">#ImageSource</font>))
        
        <b><font color="#3A3966">Case</font></b> <font color="#924B72">#SourceFiles</font>
          Files$ = ""
          <b><font color="#3A3966">For</font></b> i = 0 <b><font color="#3A3966">To</font></b> <font color="#3A3966">CountGadgetItems</font>(<font color="#924B72">#SourceFiles</font>)-1
            <b><font color="#3A3966">If</font></b> <font color="#3A3966">GetGadgetItemState</font>(<font color="#924B72">#SourceFiles</font>, i) &amp; <font color="#924B72">#PB_Explorer_Selected</font>
              Files$ +<font color="#3A3966"> GetGadgetText</font>(<font color="#924B72">#SourceFiles</font>) +<font color="#3A3966"> GetGadgetItemText</font>(<font color="#924B72">#SourceFiles</font>, i) +<font color="#3A3966"> Chr</font>(10)
            <b><font color="#3A3966">EndIf</font></b>
          <b><font color="#3A3966">Next</font></b> i
          <b><font color="#3A3966">If</font></b> Files$ &lt;&gt; ""
<font color="#3A3966">            DragFiles</font>(Files$)
          <b><font color="#3A3966">EndIf</font></b>
        
        <font color="#3A3966">; "Private" Drags only work within the program, everything else
</font>        <font color="#3A3966">; also works with other applications (Explorer, Word, etc)
</font>        <font color="#3A3966">;
</font>        <b><font color="#3A3966">Case</font></b> <font color="#924B72">#SourcePrivate</font>
          <b><font color="#3A3966">If</font></b> <font color="#3A3966">GetGadgetState</font>(<font color="#924B72">#SourcePrivate</font>) = 0
<font color="#3A3966">            DragPrivate</font>(1)
          <b><font color="#3A3966">Else</font></b>
<font color="#3A3966">            DragPrivate</font>(2)
          <b><font color="#3A3966">EndIf</font></b>
              
      <b><font color="#3A3966">EndSelect</font></b>
    
    <font color="#3A3966">; Drop event on the target gadgets, receive the dropped data
</font>    <font color="#3A3966">;
</font>    <b><font color="#3A3966">ElseIf</font></b> Event = <font color="#924B72">#PB_Event_GadgetDrop</font>
      <b><font color="#3A3966">Select</font></b> <font color="#3A3966">EventGadget</font>()
      
        <b><font color="#3A3966">Case</font></b> <font color="#924B72">#TargetText</font>
<font color="#3A3966">          AddGadgetItem</font>(<font color="#924B72">#TargetText</font>, -1,<font color="#3A3966"> EventDropText</font>())
        
        <b><font color="#3A3966">Case</font></b> <font color="#924B72">#TargetImage</font>
          <b><font color="#3A3966">If</font></b> <font color="#3A3966">EventDropImage</font>(<font color="#924B72">#ImageTarget</font>)
<font color="#3A3966">            SetGadgetState</font>(<font color="#924B72">#TargetImage</font>,<font color="#3A3966"> ImageID</font>(<font color="#924B72">#ImageTarget</font>))
          <b><font color="#3A3966">EndIf</font></b>
        
        <b><font color="#3A3966">Case</font></b> <font color="#924B72">#TargetFiles</font>
          Files$ =<font color="#3A3966"> EventDropFiles</font>()
          Count  =<font color="#3A3966"> CountString</font>(Files$,<font color="#3A3966"> Chr</font>(10)) + 1
          <b><font color="#3A3966">For</font></b> i = 1 <b><font color="#3A3966">To</font></b> Count
<font color="#3A3966">            AddGadgetItem</font>(<font color="#924B72">#TargetFiles</font>, -1,<font color="#3A3966"> StringField</font>(Files$, i,<font color="#3A3966"> Chr</font>(10)))
          <b><font color="#3A3966">Next</font></b> i
        
        <b><font color="#3A3966">Case</font></b> <font color="#924B72">#TargetPrivate1</font>
<font color="#3A3966">          AddGadgetItem</font>(<font color="#924B72">#TargetPrivate1</font>, -1, "Private type 1 dropped")
                
        <b><font color="#3A3966">Case</font></b> <font color="#924B72">#TargetPrivate2</font>
<font color="#3A3966">          AddGadgetItem</font>(<font color="#924B72">#TargetPrivate2</font>, -1, "Private type 2 dropped")
        
      <b><font color="#3A3966">EndSelect</font></b>
    
    <b><font color="#3A3966">EndIf</font></b>
    
  <b><font color="#3A3966">Until</font></b> Event = <font color="#924B72">#PB_Event_CloseWindow</font>
<b><font color="#3A3966">EndIf</font></b>

<b><font color="#3A3966">End</font></b>
</font></pre>
</body></html>
